package com.tanhua.server.controller;

import com.tanhua.model.mongo.Movement;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResultVo;
import com.tanhua.model.vo.VisitorsVo;
import com.tanhua.server.service.MovementService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/1 22:58
 */
@RestController
@RequestMapping("/movements")
public class MovementsController {

    @Autowired
    private MovementService movementService;

    /**
     * 动态保存
     * @param movement
     * @param imageContent
     * @return
     * @throws IOException
     */
    @PostMapping
    public ResponseEntity movements(Movement movement, MultipartFile imageContent[]) throws IOException {

        movementService.publishMovement(movement, imageContent);
        return ResponseEntity.ok(null);
    }


    /**
     * 查询个人动态
     * @param page
     * @param pageSize
     * @param userId
     * @return
     */
    @GetMapping("/all")
    public ResponseEntity myMovementAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pageSize, Long userId){

        PageResultVo vo = movementService.getMyMovement(page, pageSize, userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询好友动态
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseEntity friendMovent(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pageSize){

        PageResultVo vo = movementService.friendMovement(page, pageSize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 动态推荐
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pageSize){

        PageResultVo vo =  movementService.findRecommendMovement(page, pageSize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询单条动态
     */
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String movementId) {
        MovementsVo vo = movementService.findById(movementId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 动态点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){

        Integer likeCount =  movementService.like(id);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 动态取消点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable String id){
        Integer dislikeCount =  movementService.dislike(id);
        return ResponseEntity.ok(dislikeCount);
    }

    /**
     * 动态喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable String id){

        Integer count = movementService.love(id);
        return ResponseEntity.ok(count);
    }

    /**
     * 动态取消喜欢
     * @param movementId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId){

        Integer integer = movementService.unlove(movementId);
        return ResponseEntity.ok(integer);
    }


    /**
     * 谁看过我
     * @return
     */
    @GetMapping("visitors")
    public ResponseEntity queryVisitorsList(){
        List<VisitorsVo> list = movementService.queryVisitorsList();
        return ResponseEntity.ok(list);
    }


}
